package org.linlinjava.litemall.wx.task;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.core.task.Task;
import org.linlinjava.litemall.core.util.BeanUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.db.domain.LitemallOrder;
import org.linlinjava.litemall.db.domain.LitemallSpell;
import org.linlinjava.litemall.db.service.LitemallOrderService;
import org.linlinjava.litemall.db.service.LitemallSpellService;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.db.util.SpellConstant;
import org.linlinjava.litemall.db.util.OrderSpellConstant;
import org.linlinjava.litemall.wx.service.WxSpellService;

import java.util.List;

public class SpellUnpaidTask extends Task {
    private final Log logger = LogFactory.getLog(SpellUnpaidTask.class);
    private int spellId = -1;

    public SpellUnpaidTask(Integer spellId, long delayInMilliseconds){
        super("SpellUnpaidTask-" + spellId, delayInMilliseconds);
        this.spellId = spellId;
    }

    public SpellUnpaidTask(Integer spellId){
        super("SpellUnpaidTask-" + spellId,  SystemConfig.getSpellUnpaid() * 60 * 1000);
        this.spellId = spellId;
    }

    @Override
    public void run() {
        logger.info("系统开始处理延时任务---拼单活动超时未成单---" + this.spellId);
        WxSpellService wxSpellService =  BeanUtil.getBean(WxSpellService.class);
        wxSpellService.fail(this.spellId);
        logger.info("系统结束处理延时任务---拼单活动超时未成单---" + this.spellId);
    }
}
